package com.viking.filters;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;



/**
 * 自定义 一个全局过滤器工厂  (定义后即生效，不用在配置文件配置)
 * 局部过滤器：局部针对某个路由，需要在路由中进行配置
 * 全局过滤器：针对所有路由请求，一旦定义就会投入使用
 * 1、声明spring bean,实现GlobalFilter
 */
@Component
public class LogFilter implements GlobalFilter {
    Logger log= LoggerFactory.getLogger(this.getClass());

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        System.out.println("=====进入全局过滤器");
        log.info(exchange.getRequest().getPath().value());
        return chain.filter(exchange);
    }
}
